package com.codepilot.server.controller;

import com.codepilot.server.model.vo.ProblemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.codepilot.server.model.vo.CommonResult;
import com.codepilot.server.service.ProblemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/api/problem")
@Api(tags = "题目信息接口")
public class ProblemController {

    @Autowired
    private ProblemService problemService;

    /**
     * 分页返回所有题目列表
     * @param source 题目源，LC或者OJ
     * @param pageNo 第几页（从0开始）
     * @param pageSize 每页有多少条
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("支持分页返回所有题目列表")
    public CommonResult<?> getList(
            @RequestParam(value = "source", defaultValue = "LC") String source,
            @RequestParam(value = "page_no") int pageNo, 
            @RequestParam(value = "page_size") int pageSize) {
        return problemService.getList(source, pageNo, pageSize);
    }

    /**
     * 返回一个最匹配的题目信息
     * @param source 题目源，LC或者OJ
     * @param title 题目信息
     * @return
     */
    @GetMapping("/search-one")
    @ApiOperation("返回一个最匹配的题目信息")
    public CommonResult<?> searchOne(
            @RequestParam("source") String source,
            @RequestParam("title") String title
        ) {
        return problemService.searchOne(source, title);
    }

    /**
     * 返回最匹配的题目列表
     * @param source 题目源，LC或者OJ
     * @param title 题目信息
     * @param size 返回数量，默认为15
     * @return
     */
    @GetMapping("/search-list")
    @ApiOperation("返回最匹配的题目列表，支持指定返回数量")
    public CommonResult<?> searchList(
            @RequestParam("source") String source,
            @RequestParam("title") String title,
            @RequestParam(value = "size", defaultValue = "15") int size
        ) {
        return problemService.searchList(source, title, size);
    }

    @GetMapping("")
    @ApiOperation("根据problemId返回题目详细信息")
    public CommonResult<?> getProblemById(
            @RequestParam("source") String source,
            @RequestParam("problemId") int problemId) {
        return problemService.getProblemById(source, problemId);
    }

    @GetMapping("/get-uid")
    @ApiOperation("获取题目的Uid")
    public CommonResult<Integer> getProblemUid(@RequestParam("source") String source, @RequestParam("id") int id) {
        return problemService.getProblemUid(source, id);
    }

    @GetMapping("/uid")
    @ApiOperation("根据Uid获取题目信息")
    public CommonResult<ProblemVO> getProblemByUid(@RequestParam("uid") int uid) {
        return problemService.getProblemByUid(uid);
    }

}
